package com.shamine.kuaiqiao.blink.detail

import android.widget.TextView
import com.bumptech.glide.load.DecodeFormat
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.shamine.kuaiqiao.blink.R
import com.shamine.kuaiqiao.blink.basic.GlideApp
import com.shamine.kuaiqiao.blink.data.Photo

class PhotosAdapter(private val context: DetailActivity,private var size: Int): BaseQuickAdapter<Photo,BaseViewHolder>(R.layout.item_photo,null) {
    /**
     * 新增和删除时更新数量
     */
    fun setSize(size: Int){
        this.size = size
    }

    override fun convert(holder: BaseViewHolder?, photo: Photo?) {
        GlideApp.with(context)
                .load(photo?.photo?.fileUrl)
                .format(DecodeFormat.PREFER_RGB_565)
                .into(holder?.getView(R.id.photo))
        holder?.setText(R.id.date,photo?.createdAt?.substring(0,10))
        (holder?.getView(R.id.number) as TextView).text = (size - holder.adapterPosition).toString()
    }
}